package com.xgit.iov.work.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xgit.iov.common.core.util.R;
import com.xgit.iov.common.log.annotation.LogAnnotation;
import com.xgit.iov.work.model.DbdTerminal;
import com.xgit.iov.work.service.IDbdTerminalService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 终端管理
 *
 * @author william
 * @date 2020-12-04
 */

@Api(tags = "终端API")
@RestController
@RequestMapping("/terminal")
public class DbdTerminalController {

    @Autowired
    private IDbdTerminalService dbdTerminalService;

    /**
     * 查询终端列表
     */
    @ApiOperation(value = "查询终端列表")
    @GetMapping("/page")
    public R page(Page page, DbdTerminal dbdTerminal) {
        return R.ok(dbdTerminalService.selectDbdTerminalPage(page,dbdTerminal));
    }


    /**
     * 获取终端详细信息
     */
    @ApiOperation(value = "获取终端详细信息")
    @GetMapping(value = "/{id}")
    public R getById(@PathVariable("id") Long id) {
        return R.ok(dbdTerminalService.selectDbdTerminalById(id));
    }

    /**
     * 新增终端
     */
    @ApiOperation(value = "新增终端")
    @LogAnnotation("新增终端")
    @PostMapping(value = "/save")
    @PreAuthorize("@pms.hasPermission('work_terminal_add')")
    public R save(@Valid @RequestBody DbdTerminal dbdTerminal) {
        return R.ok(dbdTerminalService.insertDbdTerminal(dbdTerminal));
    }

    /**
     * 修改终端
     */
    @ApiOperation(value = "修改终端")
    @LogAnnotation("修改终端")
    @PutMapping(value = "/update")
    @PreAuthorize("@pms.hasPermission('work_terminal_edit')")
    public R update(@Valid @RequestBody DbdTerminal dbdTerminal) {
        return R.ok(dbdTerminalService.updateDbdTerminal(dbdTerminal));
    }

    /**
     * 删除终端
     */
    @ApiOperation(value = "删除终端")
    @LogAnnotation("删除终端")
	  @DeleteMapping("/{ids}")
    @PreAuthorize("@pms.hasPermission('work_terminal_del')")
    public R remove(@PathVariable Long[] ids) {
        return R.ok(dbdTerminalService.deleteDbdTerminalByIds(ids));
    }
}
